package WeeklyLog_Prototype_05.Entity;

import WeeklyLog_Prototype_05.Attachment.Attachment;

import java.io.*;

public class WeeklyLog implements Serializable {

    private String name;
    private String content;
    private String date;
    private Attachment attachment;

    public WeeklyLog(String name, String content, String date, Attachment attachment) {
        this.name = name;
        this.content = content;
        this.date = date;
        this.attachment = attachment;
    }

    public Object deepClone() throws IOException, ClassNotFoundException {
        try (ByteArrayOutputStream bao = new ByteArrayOutputStream();
             ObjectOutputStream oos = new ObjectOutputStream(bao)) {

            oos.writeObject(this);

            try (ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());
                 ObjectInputStream ois = new ObjectInputStream(bis)) {
                return ois.readObject();
            }
        }
    }

    @Override
    public String toString() {
        return name + " - " + date + " - " + content;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public Attachment getAttachment() {
        return attachment;
    }

    public void setAttachment(Attachment attachment) {
        this.attachment = attachment;
    }
}
